package com.medi.web.controller.business;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.medi.common.annotation.Log;
import com.medi.common.core.controller.BaseController;
import com.medi.common.core.domain.AjaxResult;
import com.medi.common.enums.BusinessType;
import com.medi.business.domain.DataCondition;
import com.medi.business.service.IDataConditionService;
import com.medi.common.utils.poi.ExcelUtil;
import com.medi.common.core.page.TableDataInfo;

/**
 * 数据权限-过滤条件Controller
 * 
 * @author medi
 * @date 2024-09-13
 */
@RestController
@RequestMapping("/business/datacondition")
public class DataConditionController extends BaseController
{
    @Autowired
    private IDataConditionService dataConditionService;

    /**
     * 查询数据权限-过滤条件列表
     */
    @PreAuthorize("@ss.hasPermi('business:datacondition:list')")
    @GetMapping("/list")
    public TableDataInfo list(DataCondition dataCondition)
    {
        startPage();
        List<DataCondition> list = dataConditionService.selectDataConditionList(dataCondition);
        return getDataTable(list);
    }

    /**
     * 导出数据权限-过滤条件列表
     */
    @PreAuthorize("@ss.hasPermi('business:datacondition:export')")
    @Log(title = "数据权限-过滤条件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DataCondition dataCondition)
    {
        List<DataCondition> list = dataConditionService.selectDataConditionList(dataCondition);
        ExcelUtil<DataCondition> util = new ExcelUtil<DataCondition>(DataCondition.class);
        util.exportExcel(response, list, "数据权限-过滤条件数据");
    }

    /**
     * 获取数据权限-过滤条件详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:datacondition:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(dataConditionService.selectDataConditionById(id));
    }

    /**
     * 新增数据权限-过滤条件
     */
    @PreAuthorize("@ss.hasPermi('business:datacondition:add')")
    @Log(title = "数据权限-过滤条件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DataCondition dataCondition)
    {
        return toAjax(dataConditionService.insertDataCondition(dataCondition));
    }

    /**
     * 修改数据权限-过滤条件
     */
    @PreAuthorize("@ss.hasPermi('business:datacondition:edit')")
    @Log(title = "数据权限-过滤条件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DataCondition dataCondition)
    {
        return toAjax(dataConditionService.updateDataCondition(dataCondition));
    }

    /**
     * 删除数据权限-过滤条件
     */
    @PreAuthorize("@ss.hasPermi('business:datacondition:remove')")
    @Log(title = "数据权限-过滤条件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(dataConditionService.deleteDataConditionByIds(ids));
    }
}
